Box Filter
   HOME

TheInfoList



OR:

A box blur (also known as a box linear filter) is a spatial domain linear filter in which each pixel in the resulting image has a value equal to the average value of its neighboring pixels in the input image. It is a form of low-pass ("blurring") filter. A 3 by 3 box blur ("radius 1") can be written as matrix :\frac\begin 1 & 1 & 1 \\ 1 & 1 & 1 \\ 1 & 1 & 1 \end. Due to its property of using equal weights, it can be implemented using a much simpler accumulation algorithm, which is significantly faster than using a sliding-window algorithm. Box blurs are frequently used to approximate a
Gaussian blur In image processing, a Gaussian blur (also known as Gaussian smoothing) is the result of blurring an image by a Gaussian function (named after mathematician and scientist Carl Friedrich Gauss). It is a widely used effect in graphics software, ...
. By the
central limit theorem In probability theory, the central limit theorem (CLT) establishes that, in many situations, when independent random variables are summed up, their properly normalized sum tends toward a normal distribution even if the original variables themselv ...
, repeated application of a box blur will approximate a Gaussian blur.
code doc
In the
frequency domain In physics, electronics, control systems engineering, and statistics, the frequency domain refers to the analysis of mathematical functions or signals with respect to frequency, rather than time. Put simply, a time-domain graph shows how a signa ...
, a box blur has zeros and negative components. That is, a
sine wave A sine wave, sinusoidal wave, or just sinusoid is a curve, mathematical curve defined in terms of the ''sine'' trigonometric function, of which it is the graph of a function, graph. It is a type of continuous wave and also a Smoothness, smooth p ...
with a period equal to the size of the box will be blurred away entirely, and wavelengths shorter than the size of the box may be phase-reversed, as seen when two
bokeh In photography, bokeh ( or ; ) is the aesthetic quality of the blur produced in out-of-focus parts of an image. Bokeh has also been defined as "the way the lens renders out-of-focus points of light". Differences in lens aberrations and ...
circles touch to form a bright spot where there would be a dark spot between two bright spots in the original image.


Extensions

* Gwosdek, et al. has extended Box blur to take a fractional radius: the edges of the 1-D filter are expanded with a fraction. It makes slightly better gaussian approximation possible due to the elimination of integer-rounding error. *
Mario Klingemann Mario Klingemann (born 1970 in Laatzen, Lower Saxony) is a German artist best known for his work involving neural networks, code, and algorithms. Klingemann was a Google Arts and Culture resident from 2016 to 2018, and he is considered as a pione ...
has a "stack blur" that tries to better emulate gaussian's look in one pass by stacking weights: \frac\begin 1 & 2 & 3 & 2 & 1 \end The triangular impulse response it forms decomposes to two rounds of box blur. * Stacked Integral Image by Bhatia et al. takes the weighted average of a few box blurs to fit the gaussian response curve.


Implementation

The following pseudocode implements a 3x3 box blur. Box blur (image) The example does not handle the edges of the image, which would not fit inside the kernel, so that these areas remain unblurred. In practice, the issue is better handled by: * Introducing an alpha channel to represent the absence of colors; * Extending the boundary by filling in values, ranked by quality: ** Fill in a mirrored image at the border ** Fill in a constant color extending from the last pixel ** Pad in a fixed color A number of optimizations can be applied when implementing the box blur of a radius ''r'' and ''N'' pixels: # The box blur is a
separable filter Separability may refer to: Mathematics * Separable algebra, a generalization to associative algebras of the notion of a separable field extension * Separable differential equation, in which separation of variables is achieved by various means ...
, so that only two 1D passes of averaging pixels will be needed, one horizontal and one vertical, for each pixel. This lowers the complexity from to . In digital signal processing terminology, each pass is a moving-average filter. # Accumulation. Instead of discarding the sum for each pixel, the algorithm re-uses the previous sum, and updates it by subtracting away the old pixel and adding the new pixel in the blurring range. A
summed-area table A summed-area table is a data structure and algorithm for quickly and efficiently generating the sum of values in a rectangular subset of a grid. In the image processing domain, it is also known as an integral image. It was introduced to computer g ...
can be used similarly. This lowers the complexity from to . # When being used in multiple passes to approximate a Gaussian blur, the
cascaded integrator–comb filter In digital signal processing, a cascaded integrator–comb (CIC) is an optimized class of finite impulse response (FIR) filter combined with an interpolator or decimator. A CIC filter consists of one or more integrator and comb filter pairs. In ...
construction allows for doing the equivalent operation in a single pass.


See also

*
Gaussian blur In image processing, a Gaussian blur (also known as Gaussian smoothing) is the result of blurring an image by a Gaussian function (named after mathematician and scientist Carl Friedrich Gauss). It is a widely used effect in graphics software, ...
*
Gaussian filter In electronics and signal processing mainly in digital signal processing, a Gaussian filter is a filter whose impulse response is a Gaussian function (or an approximation to it, since a true Gaussian response would have infinite impulse response) ...
*
Median filter The median filter is a non-linear digital filtering technique, often used to remove noise from an image or signal. Such noise reduction is a typical pre-processing step to improve the results of later processing (for example, edge detection on an ...


References

Image processing {{photography-stub